package com.gxuwz.stats.service.excelhandler;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.gxuwz.stats.entity.TotalWork;
import com.gxuwz.stats.service.impl.TotalWorkServiceImpl;

import java.util.ArrayList;
import java.util.List;

public class TotalWorkExcelListener extends AnalysisEventListener<TotalWork> {
    private final List<TotalWork> dataList = new ArrayList<>();
    private final TotalWorkServiceImpl workloadService;

    public TotalWorkExcelListener(TotalWorkServiceImpl workloadService) {
        this.workloadService = workloadService;
    }

    @Override
    public void invoke(TotalWork dto, AnalysisContext context) {
        dataList.add(dto);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        // 解析完成后批量保存
        workloadService.saveAllFromDTO(dataList);
    }
}
